package com.tr.rentcar.controller.houtai;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;

import com.tr.rentcar.model.dao.AdminDao;
import com.tr.rentcar.model.dao.AdminroleDao;
import com.tr.rentcar.model.dao.CarAttrDao;
import com.tr.rentcar.model.dao.CarBrandDao;
import com.tr.rentcar.model.dao.CarInfoDao;
import com.tr.rentcar.model.dao.CarStyleDao;
import com.tr.rentcar.model.dao.EmployeeDao;
import com.tr.rentcar.model.dao.FriendDao;
@WebServlet("/delete")
public class DeleteControllor extends HttpServlet {
	AdminroleDao AdminroleDao=new AdminroleDao();
	CarInfoDao CarInfoDao=new CarInfoDao();
	CarAttrDao CarAttrDao=new CarAttrDao();
	CarStyleDao CarStyleDao=new CarStyleDao();
	private static final long serialVersionUID = 1L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
		String deleteid=req.getParameter("deleteid");
		Integer deleteId=Integer.parseInt(deleteid);
		
		String array=req.getParameter("array");
		String a[]=array.trim().split(" ");
		boolean status=false;
		for (int i = 0 ; i <a.length ; i++ ) {
			Integer n=Integer.parseInt(a[i]);
			if(deleteId==1){
				status=new EmployeeDao().datelebyid(n);
				if(status=true){
					resp.sendRedirect(req.getContextPath()+"/houtaiemployeeManage");
				}else{
					req.getRequestDispatcher("/WEB-INF/jsp/error.jsp").forward(req, resp);
				}
			}
			if(deleteId==2){
				AdminroleDao.deleterole(n);
				resp.sendRedirect(req.getContextPath()+"/houtaiadminrole");
			}
			if(deleteId==3){
				CarInfoDao.deletecar(n);
				resp.sendRedirect(req.getContextPath()+"/carstore");
			}
			if(deleteId==4){
				CarStyleDao.delete(n);
				resp.sendRedirect(req.getContextPath()+"/carattr");
			}
			if(deleteId==5){
				CarAttrDao.delete(n);
				resp.sendRedirect(req.getContextPath()+"/carattrval");
			}
			if(deleteId==6){
				new FriendDao().frienddeletebyid(n);
				resp.sendRedirect(req.getContextPath()+"/friendlink");
			}
			if(deleteId==7){
				new CarBrandDao().findbyiddelete(n);
				resp.sendRedirect(req.getContextPath()+"/houtaicarbrand");
			}
			
		}}  catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			};
			/*System.out.println(a[i]);*/
	}
	
	
}
